Skip to content

Conversation

askervin
Copy link
Contributor

Using pepc simply by cloning the repo and running pepc fails on importing importlib_resources. Looking at the code, this could be avoided without installing the importlib_resources dependency in recent Python 3 versions, simply by using importlib.resources.

According to the docs, importlib.resources.files got added to the API in Python 3.9, and the only change so far, that is in Python 3.12, does not affect this code.

Therefore I'd propose getting rid of this minor inconvenience by trying to use importlib.resources.file, and only fallback to importlib_resources.files in case importlib.resources.file is not found in the API (Python older than 3.9).

I'm still leaving the TODO comment untouched as a reminder to get rid of the importlib_resources dependency when dropping support of outdated Python 3.

I tested this change with Python 3.13.5 and Python 3.9.23. They both worked fine, and they both successfully used importlib.resources.files.

@askervin askervin requested a review from dedekind as a code owner July 25, 2025 05:52
@dedekind
Copy link
Contributor

@askervin hi, oh, I completely missed this one. Apologies. Please, if you can, ping me when I do not reply next time. I'll take care of this soon.

@askervin
Copy link
Contributor Author

No problem, @dedekind! Sorry about not pinging, I already forgot this one... Definitely not a blocker, but a little thing that could help someone, anyway.

importlib_resources_files = importlib.resources.files
except:
import importlib_resources
importlib_resources_files = importlib_resources.files
Copy link
Contributor

@dedekind dedekind Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer symbols that are not supposed to be used outside of module to start with "_", as a mark that the symbol is private. This is a standard practice in Python programs.

Also there is a warning: No exception type(s) specified.

But I'll address these minor things on top of your patch, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume I need to intercept ImportError.

@dedekind dedekind merged commit dbdb693 into intel:main Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants